package com.zkingsoft.services.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zkingsoft.dao.BugTotalDao;
import com.zkingsoft.dao.ProjUserDao;
import com.zkingsoft.dao.ReportTestDao;
import com.zkingsoft.model.BugTotal;
import com.zkingsoft.model.ProjUser;
import com.zkingsoft.model.ReportTest;
import com.zkingsoft.plugin.pojo.PaginationVO;
import com.zkingsoft.services.ReportTestService;

/**
 * This field was generated by Zking.software.Codegen.
 * 
 * @date 2016-11-09 14:37
 */
@Service("reportTestService")
public class ReportTestServiceImpl implements ReportTestService {

	@Autowired
	private ReportTestDao reportTestDao;
	@Autowired
	private ProjUserDao projUserDao;

	@Autowired
	private BugTotalDao bugTotalDao;

	@Override
	public int add(ReportTest reportTest) {
		List<BugTotal> total = reportTest.getBugTotal();
		int i = reportTestDao.insert(reportTest);
		for (BugTotal bugTotal : total) {
			bugTotal.setReportTestId(reportTest.getId());
			;
			bugTotalDao.insert(bugTotal);
		}
		return i;

	}

	@Override
	public int modify(ReportTest reportTest) {

		return reportTestDao.update(reportTest);

	}

	@Override
	public int remove(List<Long> list) {

		return reportTestDao.deleteByIds(list);

	}

	@Override
	public int removeById(Long id) {

		return reportTestDao.deleteById(id);

	}

	@Override
	public int removeByModel(ReportTest reportTest) {

		return reportTestDao.deleteByModel(reportTest);

	}

	@Override
	public List<ReportTest> findInPage(ReportTest reportTest, PaginationVO pageVo) {

		return reportTestDao.selectInPage(reportTest, pageVo);

	}

	@Override
	public List<ReportTest> findByModel(ReportTest reportTest) {

		return reportTestDao.selectByModel(reportTest);

	}

	@Override
	public int findTotal(ReportTest reportTest) {

		return reportTestDao.selectTotalRecord(reportTest);

	}

	@Override
	public ReportTest findById(Long id) {

		return reportTestDao.selectById(id);

	}

	@Override
	public List<BugTotal> userBugsDetail(Long projId) {
		ProjUser projUser = new ProjUser();
		projUser.setProjId(projId);
		List<ProjUser> list = projUserDao.selectByModel(projUser);

		List<BugTotal> total = new ArrayList<BugTotal>();
		for (ProjUser obj : list) {
			BugTotal bugTotal = bugTotalDao.selectUserBugsDetail(obj.getUserId(),projId);
			if (bugTotal != null) {
				bugTotal.setUserId(obj.getUserId());
				bugTotal.setUserName(obj.getUserName());
				total.add(bugTotal);
			}
		}
		return total;
	}

}